// Author: Hiroshi Ota
// Author: TOKUMOTO Susumu
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Globalization;
using Microsoft.Practices.ComponentModel;
using Microsoft.Practices.RecipeFramework;
using Microsoft.Practices.RecipeFramework.Services;
using EnvDTE;

namespace EEst.SoftwareFactory.Actions
{
    class CopyContentsFromGP2Prj
    {
        static public void CopyContents(string srcPath, string extFilters, string destPath)
        {
            if ((!string.IsNullOrEmpty(srcPath)) && (!string.IsNullOrEmpty(destPath)))
            {
                if (Directory.Exists(srcPath))
                {
                    if (!Directory.Exists(destPath))
                    {
                        Directory.CreateDirectory(destPath, new DirectoryInfo(srcPath).GetAccessControl());
                    }
                    string[] extFilter = extFilters.Split(new char[] { ';' });
                    for (int i = 0; i < extFilter.Length; i++)
                    {
                        string[] contents = Directory.GetFiles(srcPath, extFilter[i]);
                        for (int j = 0; j < contents.Length; j++)
                        {
                            File.Copy(contents[j], destPath + Path.DirectorySeparatorChar + Path.GetFileName(contents[j]), true);
                        }
                        string[] directories = Directory.GetDirectories(srcPath, extFilter[i]);
                        for (int j = 0; j < directories.Length; j++)
                        {
                            CopyContents(srcPath + Path.DirectorySeparatorChar + Path.GetFileName(directories[j]), extFilters, destPath + Path.DirectorySeparatorChar + Path.GetFileName(directories[j]));
                        }
                    }
                }
            }
        }
    }
}
